Skip to content

netutils/ping: improve ping and ping6 for get_host error handling#3404

Open
masc2008 wants to merge 1 commit intoapache:masterfrom
masc2008:master
Open

netutils/ping: improve ping and ping6 for get_host error handling#3404
masc2008 wants to merge 1 commit intoapache:masterfrom
masc2008:master

Conversation

@masc2008
Copy link
Contributor

@masc2008 masc2008 commented Feb 17, 2026

dns look for both IPv4/v6 when do dns_query, so when do ping, it should try both ipv4 and ipv6 address before return "ping_gethostip" error.

Note: Please adhere to Contributing Guidelines.

Summary

dns lookup for both IPv4/v6 when do dns_query, so when do ping, it should try both ipv4 and ipv6 address before return "ping_gethostip" error.

Impact

The network packet losing IPv4 or IPv6 dns resolve response is quite common in network pressure test. It will return get host error without this change. It's miss-leading report to end user. It's also quite common practice for linux to use one ping support both ping and ping6.

Testing

attach two network packet that packet losing for either v4 or v6.
image

image

Error log attached as below:
ping -c 5 www.baidu.com
ERROR: ping_gethostip(www.baidu.com) failed

dns look for both IPv4/v6 when do dns_query, so when do ping,
it should try both ipv4 and ipv6 address before return "ping_gethostip" error.

Signed-off-by: Jerry Ma <masc2008@gmail.com>
****************************************************************************/

static void ping6_result(FAR const struct ping6_result_s *result)
void ping6_result(FAR const struct ping_result_s *result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change to public function

* Private Types
****************************************************************************/

struct ping6_priv_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move internal strut to header file


struct ping6_result_s;

struct ping6_info_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the reorg change to new pr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose is to let ping_result_s and ping6_result_s share same data structure. since in the callback same pointer was transferred, they will be used in different callback. same reason to ping_info_s and ping6_info_s.
if they have have private structure, and changed privately, then it will have very high risk, not easy to maintain them. considering this, should let them share same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key change is here: others are for this:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaoxiang781216 , any further concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping and ping6 is totally seperated in the old implementation, so I would suggest that:

  1. Keep the origin design, and change the above code to posix_spawn
  2. Implement ipv4/ipv6 ping in one file

either is better than the current change which couple ping/ping6 in adhoc way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say ipv4/ipv6 ping should be in one file, and that is correct way. if choose that direction: FreeBSD version of ping can match the requirement, so why do we need do such basic code again? what I did is some work with accept able cost and fully leverage the current file. if re-org based current ping code, it will a new folder with some repeated data structures. this task has afflicted me too long. I would rather give up...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say ipv4/ipv6 ping should be in one file, and that is correct way. if choose that direction: FreeBSD version of ping can match the requirement, so why do we need do such basic code again? what I did is some work with accept able cost and fully leverage the current file. if re-org based current ping code, it will a new folder with some repeated data structures. this task has afflicted me too long. I would rather give up...

Copy link
Contributor Author

@masc2008 masc2008 Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say ipv4/ipv6 ping should be in one file, and that is correct way. if choose that direction: FreeBSD version of ping can match the requirement, so why do we need do such basic code again? what I did is some work with accept able cost and fully leverage the current file. if re-org based current ping code, it will a new folder with some repeated data structures.

Copy link
Contributor Author

@masc2008 masc2008 Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further thinking, I still prefer my current direction.
First "posix_spawn" has two issues:
1. it still reports an extra "get host error" if just dns just replies one address
2. it will loop each endless if no dns replies if just do "posix_spawn" (This is a really bad problem).

Current ping/ping6 are quite well implemented, and just have a small bug. "Implement another ping" doesn't solve this bug in current ping tools.
It is allowed that several standalone tools share some common structures and functions. what I do is this such way, ping/ping6 are quite similar tools, and they should have some common things that can be leveraged by some public structures and functions. (considering that all referred functions are in "lib_ping_pub.c"). we still can configure the system to have either ping or ping6, they still goes same logic as before if just configured either one of them. If both ping and ping6 are configured it's a bug with those nuttx ping tools, we must have a solution to deal with such case.
Please consider my two cents. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants